<?php

class NHelperWebauto{

static function checkurl($url){
$parts=parse_url($url);
if(!$parts) return false; /* the URL was seriously wrong */
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
 
/* set the user agent - might help, doesn't hurt */
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 
/* try to follow redirects */
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 
/* timeout after the specified number of seconds. assuming that this script runs 
on a server, 20 seconds should be plenty of time to verify a valid URL.  */
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
 
/* don't download the page, just the header (much faster in this case) */
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
 
/* handle HTTPS links */
if($parts['scheme']=='https'){
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
 
$response = curl_exec($ch);
curl_close($ch);
 
/*  get the status code from HTTP headers */

if(preg_match('/HTTP\/1\.\d+\s+(\d+)/', $response, $matches)){
$code=intval($matches[1]);
} else {
return false;
};
 
/* see if code indicates success */
return (($code==200) );	
}
}
?>